package com.jcroke.DACGraph;
/**
 * @author jcroke
 *
 */

import com.hp.hpl.jena.query.QuerySolution;

import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.jcroke.DACGraph.DAC.DACClient;

public class Wire {
	private RDFNode _rdfNode;
	private RDFNode _rdfName;
	private RDFNode _rdfInput;
	private RDFNode _sourceRDFNode;
	private RDFNode _sourceRDFPin;
	private RDFNode _sourceRDFType;
	private RDFNode _sourceRDFTypeClass;

	public static final String NAME = "name";
	public static final String INPUT = "input";
	public static final String WIRE = "wire";
	public static final String BOLT = "bolt";
	public static final String SUBSCRIPTION = "subscription";
	public static final String TYPE = "type";
	public static final String TYPECLASS = "typeClass";

	public Wire(DACClient dac, QuerySolution qs) {
		this._rdfName = qs.get(NAME);
		this._rdfInput = qs.get(INPUT);
		this._rdfNode = qs.get(WIRE);
		

		ResultSet resultSet = dac.sparql(String.format(
				SPARQL.WIRE_DESCRIPTION_QUERY_TEMPLATE, getIRI()));
		if (resultSet.hasNext()) {
			QuerySolution es = resultSet.next();
			this._sourceRDFNode = es.get(BOLT);
			this._sourceRDFPin = es.get(SUBSCRIPTION);
			this._sourceRDFType = es.get(TYPE);
			this._sourceRDFTypeClass = es.get(TYPECLASS);
		}
	}

	public RDFNode getRDFName() {
		return _rdfName;
	}
	
	public Signature getSignatureElement() {
		return (new Signature(_rdfInput, _sourceRDFNode, _sourceRDFPin, _sourceRDFType, _sourceRDFTypeClass));
	}

	public String getIRI() {
		return (_rdfNode.toString());
	}
	
	public RDFNode getSourceRDFNode() {
		return _sourceRDFNode;
	}
	
	public String getSourceIRI() {
		return _sourceRDFNode.toString();
	}
	
	public String toSring() {
		return substrIRI();
	}
	
	
	public String substrIRI() {
		return (_rdfNode.toString().split("#")[1]);
	}	
}
